package com.chuxing.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.chuxing.config.PermissionsState;
import com.chuxing.config.SecurityRole;
import com.chuxing.domain.Result;
import com.chuxing.exception.GenericException;
import com.chuxing.exception.UnauthorizedException;
import com.chuxing.system.service.ConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiuQi
 * @create 2025-05-20-15:24
 */
@RestController
@RequestMapping("/system/config")
@Tag( name = "系统设置服务", description = "系统设置服务相关接口")
@RequiredArgsConstructor
public class ConfigController {
    private final ConfigService configService;

    @Operation(summary = "清空报名信息", description = "清空报名信息")
    @PostMapping("/enroll")
    public Result<Object> enroll() {
        // 检查用户是否已登录
        if (!StpUtil.isLogin()) {
            throw new UnauthorizedException(PermissionsState.NOT_LOGIN);
        }
        // 检查用户是否具有超级管理员角色
        if (!StpUtil.hasRole(SecurityRole.ROLE_SUPER_ADMIN)) {
            throw new GenericException(PermissionsState.PERMISSION_NOT_ENOUGH);
        }
        configService.enroll();
        return Result.success();
    }

    @Operation(summary = "检查考试分数线", description = "检查考试分数线")
    @GetMapping("/checkExamScoreLine/{score}")
    public Result<Object> checkExamScoreLine(@PathVariable("score") Integer score){
        // 检查用户是否已登录
        if (!StpUtil.isLogin()) {
            throw new UnauthorizedException(PermissionsState.NOT_LOGIN);
        }
        // 检查用户是否具有超级管理员角色
        if (!StpUtil.hasRole(SecurityRole.ROLE_SUPER_ADMIN)) {
            throw new GenericException(PermissionsState.PERMISSION_NOT_ENOUGH);
        }
        configService.checkExamScoreLine(score);
        return Result.success();
    }
    
    @Operation(summary = "检查面试分数线", description = "检查面试分数线")
    @GetMapping("/checkInterviewScoreLine/{score}")
    public Result<Object> checkInterviewScoreLine(@PathVariable("score") Integer score){
        // 检查用户是否已登录
        if (!StpUtil.isLogin()) {
            throw new UnauthorizedException(PermissionsState.NOT_LOGIN);
        }
        // 检查用户是否具有超级管理员角色
        if (!StpUtil.hasRole(SecurityRole.ROLE_SUPER_ADMIN)) {
            throw new GenericException(PermissionsState.PERMISSION_NOT_ENOUGH);
        }
        configService.checkInterviewScoreLine(score);
        return Result.success();
    }
}
